package com.lin.controller.admin;

import com.lin.commons.Result;
import com.lin.entity.CarInformation;
import com.lin.service.CarInformationService;
import com.lin.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Created by Lin Weihong
 * @Time on 2021/11/24 19:23
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/car")
public class AdminCarInformationController {

    @Autowired
    CarInformationService carInformationService;

    @GetMapping("/carList")
    public DataVO<CarInformation> carList(Integer page,Integer limit) {
        return carInformationService.adminFindData(page, limit);
    }

    @PostMapping("/addCar")
    public Result addCar(@RequestBody CarInformation carInformation) {
        boolean save = carInformationService.save(carInformation);
        if (save) {
            return Result.success();
        }else {
            return Result.failure();
        }
    }

    @DeleteMapping("/delete/{carId}")
    public Result deleteCar(@PathVariable("carId") Integer carId) {
        boolean remove = carInformationService.removeById(carId);
        if (remove) {
            return Result.success();
        }else {
            return Result.failure();
        }
    }

    @PostMapping("/updateCar")
    public Result updateCar(@RequestBody CarInformation carInformation) {
        boolean update = carInformationService.updateById(carInformation);
        if (update) {
            return Result.success();
        }else {
            return Result.failure();
        }
    }
}
